//
//  ZH_TeacherCollectionViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/19.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_TeacherCollectionViewCell.h"
@interface ZH_TeacherCollectionViewCell()
@property (nonatomic,weak)UIImageView *pngView;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIButton *typeButton;
@property (nonatomic,weak)UILabel *mapLabel;
@property (nonatomic,weak)UIButton *collectButton;
@end
@implementation ZH_TeacherCollectionViewCell
///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[ZH_TeacherCollectionViewCell class] forCellWithReuseIdentifier:@"ZH_TeacherCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"ZH_TeacherCollectionViewCell" forIndexPath:indexPath];
}
//初始化
-(void)initDefault
{
    
}
///加载子视图约束
-(void)loadSubviewConstraints
{
    [self.pngView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(0));
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(122));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pngView.mas_bottom).offset(FITSCALE(18));
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
//        make.height.mas_equalTo(FITSCALE(13));
    }];
    [self.typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pngView.mas_bottom).offset(FITSCALE(14));
        make.right.equalTo(self.contentView).offset(FITSCALE(-10));
        make.width.mas_equalTo(FITSCALE(56));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.mapLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(21));
        make.left.equalTo(self.titleLabel);
    }];
    [self.collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mapLabel);
        make.right.equalTo(self.contentView).offset(FITSCALE(-29));
    }];
    
}
- (void)updateUI:(NSMutableDictionary *)data{
    [self.pngView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"head"]]] placeholderImage:nil];
    self.titleLabel.text = data[@"nickname"];
    self.mapLabel.text = [NSString stringWithFormat:@"%@KM",data[@"distance"]];
    NSString *string = [NSString stringWithFormat:@"%@",data[@"is_attention"]];
    if ([string isEqualToString:@"1"]) {
        [self.typeButton setTitle:@"已认证" forState:UIControlStateNormal];
    }else{
        [self.typeButton setTitle:@"未认证" forState:UIControlStateNormal];
    }
}
#pragma mark - getter,setter
- (UIImageView *)pngView{
    if (!_pngView) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = kFontColorRed;
        image.contentMode = UIViewContentModeScaleToFill;
        image.layer.masksToBounds = YES;
        [self.contentView addSubview:_pngView = image];
    }
    return _pngView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"小温暖" font:kFontSize_26];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UIButton *)typeButton{
    if (!_typeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"已认证" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#CBFFF8"];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_typeButton = button];
    }
    return _typeButton;
}
- (UILabel *)mapLabel{
    if (!_mapLabel) {
        UILabel *label = [UILabel createLabelWithText:@"111.11KM" font:kFontSize_22];
        label.textColor = [UIColor colorWithHexString:@"#01CAAF"];
        [self.contentView addSubview:_mapLabel = label];
    }
    return _mapLabel;
}
- (UIButton *)collectButton{
    if (!_collectButton) {
        UIButton *button = [UIButton createButtonWithTitle:@"" normalImage:@"icon_fllow" pressImage:@"icon_fllow_selected" target:self action:nil];
        [self.contentView addSubview:_collectButton = button];
    }
    return _collectButton;
}
@end
